﻿using System;
using System.Windows.Threading;

namespace QueryResource.Common
{
    public static  class InvokeExpand
    {
        public static void InvokeEx(this DispatcherObject dobj, Action action,object[] objs = null)
        {
            if (!dobj.Dispatcher.CheckAccess())    //System.Threading.Thread.CurrentThread != dobj.Dispatcher.Thread)
            {
                dobj.Dispatcher.Invoke(action, objs);
            }
            else
            {
                action();
            }
        }

        public static void BeginInvokeEx(this DispatcherObject dobj, Action action, object[] objs = null)
        {
            if (!dobj.Dispatcher.CheckAccess())      //System.Threading.Thread.CurrentThread != dobj.Dispatcher.Thread)
            {
                dobj.Dispatcher.BeginInvoke(action, objs);
            }
            else
            {
                action();
            }
        }
    }
}
